<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    const masterMind = (solution, guess) => {
      let m = 0, n = 0,
        obj = {
          'R': 0,
          'G': 0,
          'B': 0,
          'Y': 0
        };
      for (let i = 0; i < 4; i++) {
        if (solution[i] === guess[i]) {
          m++
        } else {
          if (obj[solution[i]]++ < 0) n++
          if (obj[guess[i]]-- > 0) n++
        }
      }
      return [m, n]
    }

    console.log(masterMind('RGBY', 'GGRR'));
  </script>
</body>

</html>